package com.qf.controller;

import com.qf.vo.R;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author ASUS
 * @version V1.0
 * @Project work
 * @Package com.qf.controller
 * @Date 2021/10/14 17:43
 */
@RestController
@CrossOrigin(allowCredentials = "true")
public class UserController {

    @RequestMapping("/doLogin")
    public R login(@RequestParam String username, @RequestParam String password){
        Subject subject = SecurityUtils.getSubject();
        subject.login(new UsernamePasswordToken(username,password));
        return R.ok();
    }

    @GetMapping("/logout")
    public String logout(){
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
        return "ok!";
    }
}
